<?php
namespace App\Admin\Controllers\Garage;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

use App\Models\Garage\Area as ThisModel;

class AreaController extends AdminController
{
    protected $title = '区域管理';

    protected function grid()
    {
        $types = ThisModel::getTypes();

        $grid = new Grid(new ThisModel);

        $grid->model()->orderBy('id', 'desc');

        $grid->column('id', __('ID'))->sortable();
        $grid->column('type', __('Type'))->using($types);
        $grid->column('title', __('Title'));
        $grid->column('nickname', __('Nickname'));
        $grid->column('abbreviation', __('Abbreviation'));
        $grid->column('alias', __('Alias'));

        // $grid->column('created_by', __('Created by'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        $grid->filter(function ($filter) use ($types) {
            $filter->disableIdFilter();
            $filter->column(1/3, function ($filter) {
                $filter->equal('id', __('ID'));
                $filter->equal('title', __('Title'));
            });
            $filter->column(1/3, function ($filter) use ($types) {
                $filter->equal('type', __('Type'))->select($types);
                $filter->equal('nickname', __('Nickname'));
            });
            $filter->column(1/3, function ($filter) {
                $filter->equal('abbreviation', __('Abbreviation'));
                $filter->equal('alias', __('Alias'));
            });
        });

        return $grid;
    }
    protected function detail($id)
    {
        $show = new Show(ThisModel::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }
    protected function form()
    {
        $types = ThisModel::getTypes();

        $form = new Form(new ThisModel);

        // $form->display('id', __('ID'));
        $form->select('type', __('Type'))->options($types);
        $form->text('title', __('Title'));
        $form->image('nickname', __('Nickname'));
        $form->text('abbreviation', __('Abbreviation'));
        $form->image('alias', __('Alias'));
        // $form->display('created_at', __('Created At'));
        // $form->display('updated_at', __('Updated At'));

        $form->disableViewCheck()
            ->disableCreatingCheck();

        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
        });

        return $form;
    }
}
